<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/8 0008
 * Time: 下午 5:24
 */
namespace app\admin\controller;

use app\common\BaseHelper;
use app\lib\exception\ParameterException;
use think\Request;

class Uploadfile extends Base{
    public function upload(){
        $file = Request::instance()->file('file');
        if($file){
            $info = $file->validate(config('upload.UPLOAD_RULE'))->move(config('path.Upload_path'));
            if($info){
                return show(config('status.SUCCESS_STATUS'),'图片上传成功',$info->getSaveName());
            }else{
                throw new ParameterException([
                    'msg' => $file->getError(),
                ]);
            }

        }else{
            throw new ParameterException([
                'msg' => '没有获取到上传图片信息'
            ]);
        }


    }

    public function uploadcertFile(){
        $file = Request::instance()->file('file');
        if($file){
            $time = date('Ymd',time());
            $pathname = BaseHelper::getUUID22();
            $path = config('path.certFile_path').$time.'/'.$pathname;
            $info = $file->validate(config('upload.CERT_RULE'))->move($path,false);
            if($info){
                return show(config('status.SUCCESS_STATUS'),'图片上传成功',$time.'/'.$pathname.'/'.$info->getSaveName());
            }else{
                throw new ParameterException([
                    'msg' => $file->getError(),
                ]);
            }

        }else{
            throw new ParameterException([
                'msg' => '没有获取到上传图片信息'
            ]);
        }


    }
}